package com.tzpay.tzpay.bean;

import com.tzpay.tzpay.api.AppShopFunPay;
import com.tzpay.tzpay.api.AppShopInfo;
import com.tzpay.tzpay.api.TzLoginResponse;

import java.util.List;

/**
 * Created by Administrator on 2016/4/8 0008.
 */
public class UserInfo {
    private static UserInfo instance;

    public static UserInfo getInstance() {
        if (instance == null) {
            synchronized (UserInfo.class) {
                if (instance == null) {
                    instance = new UserInfo();
                }
            }
        }
        return instance;
    }

    private TzLoginResponse response;

    private String userName;

    private String password;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public TzLoginResponse getResponse() {
        return response;
    }

    public void setResponse(TzLoginResponse response) {
        this.response = response;
        setMerchantIbfo();
    }

    public String getShopName() {
        return shopName;
    }

    public String getShopTel() {
        return shopTel;
    }

    public String getShopLogo() {
        return shopLogo;
    }

    private String shopName = "";
    private String shopLogo = "";
    private String shopTel = "";
    private String merchantKey = "";
    private String shopId = "";
    private String merchantNo = "";
    private String subMerchantNo = "";
    private String merchantDataKey = "";
    private String channel = "";
    private String busicType = "";
    private String backUrl = "";

    private String merchantPwd = "";
    private String ledgerDetail = "";
    private String attach = "";

    private String funcId = "";

    public String getMerchantKey() {
        return merchantKey;
    }

    public String getShopId() {
        return shopId;
    }

    public String getMerchantNo() {
        return merchantNo;
    }

    public String getSubMerchantNo() {
        return subMerchantNo;
    }

    public String getMerchantDataKey() {
        return merchantDataKey;
    }

    public String getChannel() {
        return channel;
    }

    public String getBusicType() {
        return busicType;
    }

    public String getBackUrl() {
        return backUrl;
    }

    public String getMerchantPwd() {
        return merchantPwd;
    }

    public String getLedgerDetail() {
        return ledgerDetail;
    }

    public String getAttach() {
        return attach;
    }

    public String getFuncId() {
        return funcId;
    }

    public void setFuncId(String funcId) {
        this.funcId = funcId;
    }

    public void setMerchantIbfo() {
        if (response != null && response.isSuccess()) {
            AppShopInfo shopInfo = response.getAppShopInfo();
            if (shopInfo != null) {
                merchantKey = shopInfo.getOrgKey();
                shopId = shopInfo.getShopId();
                shopName = shopInfo.getShopName();
                shopLogo = shopInfo.getShopLogo();
                shopTel = shopInfo.getShopTel();
            }

            List<AppShopFunPay> shopFunPays = response.getAppShopFunction();

            if (shopFunPays != null && shopFunPays.size() > 0) {
                AppShopFunPay shopFunPay = shopFunPays.get(0);
                merchantNo = shopFunPay.getMerchantId();
                subMerchantNo = shopFunPay.getParam1();
                channel = shopFunPay.getParam2();
                busicType = shopFunPay.getParam3();
                backUrl = shopFunPay.getParam4();
//                ledgerDetail = shopFunPay.getParam5();
                attach = shopFunPay.getParam6();
                merchantPwd = shopFunPay.getParam7();
                merchantDataKey = shopFunPay.getParam8();
                funcId = shopFunPay.getFuncId();
            }
        }
    }

    @Override
    public String toString() {
        return "UserInfo{" +
                "response=" + response +
                ", userName='" + userName + '\'' +
                ", password='" + password + '\'' +
                ", shopName='" + shopName + '\'' +
                ", shopLogo='" + shopLogo + '\'' +
                ", shopTel='" + shopTel + '\'' +
                ", merchantKey='" + merchantKey + '\'' +
                ", shopId='" + shopId + '\'' +
                ", merchantNo='" + merchantNo + '\'' +
                ", subMerchantNo='" + subMerchantNo + '\'' +
                ", merchantDataKey='" + merchantDataKey + '\'' +
                ", channel='" + channel + '\'' +
                ", busicType='" + busicType + '\'' +
                ", backUrl='" + backUrl + '\'' +
                ", merchantPwd='" + merchantPwd + '\'' +
                ", ledgerDetail='" + ledgerDetail + '\'' +
                ", attach='" + attach + '\'' +
                '}';
    }
}
